<?php

    /**
     *      [Discuz!] (C)2001-2099 Comsenz Inc.
     *      This is NOT a freeware, use is subject to license terms
     *      $Id: mobile.php 31964 2012-10-26 07:27:36Z zhangjie $
     */

    define('IN_MOBILE_API', 1);
    chdir('../../../');

    require_once 'source/plugin/cloud/cloud.class.php';

    $_GET['mobile'] = 'no';

    $modules = array(
        'addition',
        //下面都是新添加的接口
        //应用(cloud_app)
        'app_add', 'app_update', 'app_status_update', 'app_info_get', 'app_all_search', 'app_all_find', 'app_storeId_get','app_all_not_limit_find',
        //应用支付宝设置(cloud_app_alipay)
        'app_alipay_find', 'app_alipay_update',
        //应用地区(cloud_app_district)
        'area_add', 'area_update', 'area_status_update', 'area_all_find', 'area_status_find', 'area_find', 'area_find_upid',
        //应用地区滚动广告(cloud_district_adpic)
        'adpic_add', 'adpic_update', 'adpic_delete', 'adpic_district_find',
        //一键呼叫(cloud_district_call)
        'call_add', 'call_delete', 'call_district_find', 'call_update',
        //应用管理员(cloud_app_manage)
        'manager_add', 'manager_status_update', 'manager_info_get', 'manager_all_find', 'manager_login', 'manager_logout','manager_role',
        'manager_password_update','manager_app_find','manager_password_reset',
        //用户(cloud_users)
        'users_login', 'users_update', 'users_status_update', 'users_info_get', 'users_all_find', 'users_all_search',
        'users_logout', 'users_register', 'users_password_update', 'users_mobile_login','users_number','users_repassword_update',
        //用户收货地址(cloud_shiping_address)
        'shipping_address_add', 'shipping_address_update', 'shipping_address_delete', 'shipping_address_all_find',
        //提醒(cloud_remind)
        'remind_add', 'remind_all_find', 'remind_delete', 'remind_update',
        //收藏(cloud_user_collect)
        'collect_add', 'collect_delete', 'collect_all_find', 'collect_all_search', 'collect_for_user',
        //产品分类(cloud_category)
        'category_add', 'category_all_find', 'category_delete', 'category_update', 'category_select', 'product_category_upload',
        //产品规格分类(cloud_standards)
        'standards_add', 'standards_delete', 'standards_update', 'standards_all_find',
        //产品详细(cloud_product)
        'product_add', 'product_all_find', 'product_all_search', 'product_category_find', 'product_delete', 'product_info_get',
        'product_category_order_find', 'product_recommend_find', 'product_viewnum_update','product_all_full_find',
        'product_recommend_order_find','product_all_order_find', 'product_category_order_red_find',
        //产品图片(cloud_product_photo)
        'product_photo_delete', 'product_photo_find', 'product_photo_get', 'product_update', 'product_attachment_upload',
        //产品评价(cloud_product_assess)
        'assess_product_add', 'assess_product_delete', 'assess_product_find', 'assess_product_user_find', 'assess_product_info_find',
        'assess_product_area',
        //产品评价支持(cloud_assess_click)
        'assess_product_support',
        //资讯分类(cloud_column)
        'column_add', 'column_delete', 'column_update', 'column_all_find', 'column_area_find',
        //资讯(cloud_article)
        'article_add', 'article_delete', 'article_update', 'article_info_get', 'article_column_find', 'article_attachment_get','article_column_all_find',
        //订单详细(cloud_orders)
        'orders_add', 'orders_red_add','orders_all_find', 'orders_delete', 'orders_info_get', 'orders_update', 'orders_user_find',
        'orders_not_finish_find', 'orders_finish_find','orders_area_search','orders_express_update',
        //购物车(cloud_shopping_cart)
        'shopping_cart_add', 'shopping_cart_all_delete', 'shopping_cart_delete', 'shopping_cart_find', 'shopping_cart_update',
        //客户留言(cloud_message)
        'message_add', 'message_delete', 'message_view_update', 'message_replay_update', 'message_district_find',
        //公共
        'addition', 'affix_image', 'affix_audio', 'article_attachment_upload', 'product_attachment_upload',
        //推送接口信息的添加
        'push_android_add', 'push_ios_add', 'push_ios_message','push_ios_find','jpush_android',
        //新增推送api
        'push_all_find','push_type_find','push_all_message',
        //公共上传附件的接口
        'attachment_upload',
        //系统功能维护(cloud_function)
        'function_add','function_update','function_status_find','function_all_find','function_all_pid_find',
        //应用功能维护(cloud_app_function)
        'app_function_add','app_function_all_find','app_function_delete','app_function_not_select',
        //应用角色维护(cloud_app_role)
        'app_role_add','app_role_update','app_role_status_find','app_role_all_find',
        //角色权限维护(cloud_role_purview)
        'role_purview_add','role_purview_all_find','role_purview_delete','role_purview_not_select',
        //应用 树形结构 json
        'treeJson_show',
        //咨询(社区医疗)
        'consult_category_add', 'consult_category_delete', 'consult_category_update', 'consult_category_all_find',
        'consult_add', 'consult_delete', 'consult_update', 'consult_all_find',
        'consult_post_add', 'consult_post_delete', 'consult_post_update', 'consult_post_info_get',
        //签到(曲江旅游)
        'spot_add','spot_all_find','spot_attachment_upload','spot_update','spot_delete','spotsign_all_find','spotsign_update','spotsign_find',
        //照片墙(曲江旅游)
        'photowall_all_list','photowall_add','photowall_all_find','photowall_audit','photowall_delete',
        //支付代码
        'cloud_pay_index', 'cloud_pay_notify_url', 'cloud_pay_back_url','cloud_pay_alipay','cloud_pay_message',
        //优惠券
        'coupon_rule_add','coupon_rule_all_find','coupon_rule_delete','coupon_add','coupon_get_info','coupon_status_update','coupon_token_info',
        //短信api
        'message_status','send_message',
        //以下是测试
        'porter', 'rome', 'upload',
        //邮费设计
        'express_all_find','express_info_get','express_info_add','express_info_edit','express_info_delete','express_area_reckon',
    );

    if (!in_array($_GET['module'], $modules)) {
        cloud_core::result(array('error' => 'module_not_exists'));
    }
    $_GET['version'] = !empty($_GET['version']) ? intval($_GET['version']) : 1;
    $_GET['version'] = $_GET['version'] > MOBILE_PLUGIN_VERSION ? MOBILE_PLUGIN_VERSION : $_GET['version'];

    if (empty($_GET['module']) || empty($_GET['version']) || !preg_match('/^[\w\.]+$/', $_GET['module']) || !preg_match('/^[\d\.]+$/', $_GET['version'])) {
        cloud_core::result(array('error' => 'param_error'));
    }

    if (!empty($_POST['request']) || !empty($_GET['request'])) {
        cloud_core::jsonToRequest();
    }

    if (stripos($_GET['module'], '_pay_')) {
        require_once 'source/class/class_core.php';
        C::app()->init();
        $payfile = 'source/plugin/cloud/api/pay/' . $_GET['module'] . '.php';
        if (file_exists($payfile)) {
            require_once $payfile;
        }else{
            cloud_core::result(array('error' => 'module_not_exists'));
        }
    }
    else {
        $apifile = 'source/plugin/cloud/api/' . $_GET['version'] . '/' . $_GET['module'] . '.php';
        if (file_exists($apifile)) {
            require_once $apifile;
        }
        else {
            if ($_GET['version'] > 1) {
                for ($i = $_GET['version']; $i >= 1; $i--) {
                    $apifile = 'source/plugin/cloud/api/' . $i . '/' . $_GET['module'] . '.php';
                    if (file_exists($apifile)) {
                        $_GET['version'] = $i;
                        require_once $apifile;
                        break;
                    }
                    elseif ($i == 1 && !file_exists($apifile)) {
                        cloud_core::result(array('error' => 'module_not_exists'));
                    }
                }
            }
            else {
                cloud_core::result(array('error' => 'module_not_exists'));
            }
        }
    }

?>